<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p id="demo">id="demo" 的 p 元素</p>
<p> 点击按钮修改 id="demo" 的 p 元素内容</p>
<button onclick="myFunction()">点我</button>
	<textarea name="" id="text" cols="30" rows="10">这里输入的数据将保存为txt中</textarea>
       <button id="save" type="button">保存</button>

<script>
function myFunction() {
    document.querySelector("#demo").innerHTML = "Hello World!";
}
	document.querySelector('#save').addEventListener('click', saveFile);
       function fakeClick(obj) { 
         var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    obj.dispatchEvent(ev);
  }

  function exportRaw(name, data) {
    var urlObject = window.URL || window.webkitURL || window;
    var export_blob = new Blob([data]);
    var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
    save_link.href = urlObject.createObjectURL(export_blob);
    save_link.download = name;
    fakeClick(save_link);
  }

  function saveFile(){
    var inValue  = document.querySelector('#text').value;
    exportRaw('test.txt', inValue);
  }
</script>

</body>
</html>